/**
 * 注册路由
 */

const register = require('../../modules/register')


module.exports = (req, res) => {
  let user_name = req.body.name
  let user_password = req.body.password
  let user_age = req.body.age
  let user_birthday = req.body.birthday
  let user_phone = req.body.phone
  let user_sex = req.body.sex
  if (!user_name || !user_password || !user_age || !user_birthday || !user_phone || !user_sex) {
    return res.status(200).json({msg: '参数错误', code: 400})
  }
  
  // 对参数进行复制
  let data = Object.assign({}, req.body)

  // 保存进数据库
  register.saveDb(data).then(suc => {
    return res.status(200).json({msg: suc.msg, code: suc.code})
  }).catch(err => {
    console.log(err)
    return res.status(200).json({msg: '服务器返回错误，请稍后重试', code: 500})
  })
}


